const {
	Controller
} = require('uni-cloud-router')
const uniID = require('uni-id')
module.exports = class TradeController extends Controller {
	async getWithdrawList() {
		let {
			isMember = true,
			pageNum = 1,
			pageSize = 10,
			userId
		} = this.ctx.data
		try{
			let result = await this.service.trade.getWithdrawList({
				pageNum,
				pageSize,
				isMember,
				userId
			})
			return {
				code: 200,
				result
			}
		}catch(e){
			return {
				code: 500,
				message: e.message
			}
		}
	}
	async getUserIncomeDetail() {
		let {
			startDate, 
			endDate, 
			pageNum, 
			pageSize,
			tradeType,
			userId
		} = this.ctx.data
		if (!userId) {
			return {
				code: 500,
				msg: '参数错误'
			}
		}
		return this.service.trade.getIncomeDetail({
			startDate, endDate, pageNum, pageSize, tradeType, userId
		})
	}
	
	async auditWithdrawApply() {
		const {
			applyId,
			action,
			note
		} = this.ctx.data
		if (!applyId || !action || (action !== 'PASSED' && action !== 'REJECTED') || (action === 'REJECTED' && !note)) {
			return {
				code: 500,
				msg: '参数错误'
			}
		}
		return this.service.trade.auditWithdrawApply(applyId, action, note)
	}
	
	async auditManualWithdrawApply() {
		const {
			applyId,
			action,
			note
		} = this.ctx.data
		if (!applyId || !action || (action !== 'PASSED' && action !== 'REJECTED') || (action === 'REJECTED' && !note)) {
			return {
				code: 500,
				msg: '参数错误'
			}
		}
		return this.service.trade.auditManualWithdrawApply(applyId, action, note)
	}
}
